package com.yyl.render.render

import android.content.Context
import android.view.Surface
import com.yyl.render.egl.EGLSurfaceView
import com.yyl.render.egl.Renderer

abstract class BaseRender : YYLRender(), Renderer {

    lateinit var surfaceView: EGLSurfaceView

    fun attachSurface(surfaceView: EGLSurfaceView) {
        this.surfaceView = surfaceView
        this.surfaceView.render = this
        onStartRender(surfaceView.context)
    }

    abstract fun onStartRender(context: Context)

    fun requestRender() {
        surfaceView.requestRender()
    }

    fun isWaiting() = surfaceView.isWaiting()


    fun setTransformMatrix(
        translateX: Float,
        translateY: Float,
        scaleX: Float,
        scaleY: Float,
        degree: Int,
        mirror: Int
    ) {
        nativeSetTransformMatrix(translateX, translateY, scaleX, scaleY, degree, mirror)
        requestRender()
    }

    fun onDestroy() {
        nativeOnDestroy()
    }

    override fun onSurfaceCreated() {
        nativeOnSurfaceCreated()
    }

    override fun onSurfaceChanged(width: Int, height: Int) {
        nativeOnSurfaceChanged(width, height)
    }

    override fun onSurfaceDrawFrame() {
        nativeOnSurfaceDrawFrame()
    }

    override fun onSurfaceDestroy() {
        nativeOnSurfaceDestroy()
    }
}